<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0,user-scalable=no,maximum-scale=1.0,minimun-scale=1.0">
    <title>工资计算</title>
    <script src="jquery.min.js"></script>
    <script src="money.js"></script>
    <link rel="stylesheet" href="money.css">
</head>

<body>
    <div class="salary_box">
        <h3>单日统计</h3>
        <input type="submit" value="合计" onclick="addSalary()">&nbsp;&nbsp;&nbsp;
        <input type="submit" value="归零" onclick="reMove()">
        <div class="salary_son_box"></div>
    </div>
    <div class="father_box">
        <div class="day_box">
            <h4>单日统计</h4>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;数量&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;
            单价&nbsp;&nbsp;&nbsp;

            &nbsp;&nbsp;合计<br>
            <input type="number" id="mount"> x <input type="number" id="price"> = <span id="day_total"></span><br><br>

            

            <input type="submit" value="计算" onclick="myFunction()">

        </div>

        <div class="hour_box">
            <h4>计时统计</h4>
            <p>计时小时</p>

            <input type="number" id="hours"><br><br>
            <input type="submit" value="计算" onclick="myFunction1()">
        </div>

        <div class="paper_box">
            <h4>页总计</h4>
            <span id="paper_total"></span><br>
            <input type="submit" value="合计" onclick="paperSalary()">&nbsp;&nbsp;&nbsp;
            <input type="submit" value="归零" onclick="emptySalary1()">
        </div>
        <div class="month_box">
            <h4>总工资</h4>
            <span id="m_total"></span><br>
            <input type="submit" value="合计" onclick="monthSalary()">&nbsp;&nbsp;&nbsp;
            <input type="submit" value="归零" onclick="emptySalary()">
        </div>

    </div>
</body>
<script>
    // 单日单个存储数组
    var arr = [];
    // 单页总价存储数组
    var arr1 = [];
    // 月度总额存储数组
    var arr2 = [];
    var month_sum = 0;
    var paper_sum = 0;
    var day_sum = 0;

    //单日统计
    function myFunction() {
        var mount = document.getElementById("mount").value;
        var price = document.getElementById("price").value;
        var res = mount * price;
        var total = Math.floor(res * 1000) / 1000;

        if (total != null) {
            document.getElementById("day_total").innerHTML = total;
            var p = $("<p></p>");
            p.html(mount + ' x ' + price + ' = ' + total);
            $(".salary_son_box").append(p);
            $("#mount,#price").val("");
            arr.push(total);


        }
    }

    // 计时统计
    function myFunction1() {
        var hours = document.getElementById("hours").value;
        var h_total = hours * 16;
        if (h_total != null) {
            var p = $("<p></p>");
            p.html(hours + ' 小时 ' + ' = ' + h_total);
            $(".salary_son_box").append(p);
            $("#hours").val("");
            arr.push(h_total);


        }
    }

    // 单日统计重置
    function reMove() {
        arr.splice(0, arr.length);

        

        $(".salary_son_box").empty();

        day_sum = 0;

    }

    // 单页重置
    function emptySalary1() {
        while (arr1.length > 0) {
            arr1.pop();
        }

        $("#paper_total").html("");
        $(".salary_son_box").empty();
        paper_sum = 0;

    }
    // 月度重置
    function emptySalary() {
        arr1.splice(0, arr1.length);
        while (arr2.length > 0) {
            arr2.pop();
        }

        $("#m_total").html("");
        $(".salary_son_box").empty();
        month_sum = 0;

    }

    // 单日总数统计
    function addSalary() {
        var p = $("<p></p>");
        for (var i = 0; i < arr.length; i++) {
            day_sum += arr[i];
        }
        arr1.push(Math.floor(day_sum*1000)/1000);
        arr2.push(Math.floor(day_sum*1000)/1000);
        p.html('单日总额' + '=' + Math.floor(day_sum*1000)/1000);
        $(".salary_son_box").append(p);
        $("#paper_total").html(arr1+",");
    }

    // 单页统计
    function paperSalary() {
        for (var i = 0; i < arr1.length; i++) {
            paper_sum += arr1[i];
        }
        $("#paper_total").html(Math.floor(paper_sum*1000)/1000);

    }

    // 月度统计
    function monthSalary() {
        for (var i = 0; i < arr2.length; i++) {
            month_sum += arr2[i];
        }
        $("#m_total").html(Math.floor(month_sum*1000)/1000);



    }
</script>

</html>